import Vue from 'vue'
import Router from 'vue-router'
import Layout from '@/layout'
import Home from '@/views/index.vue'
import login from '@/views/login/index.vue'
Vue.use(Router)

// 基础路由
const routine = [
  {
    path: '/login',
    name: 'login',
    hidden: true,
    component: login,
    meta: { title: '登录' }
  },
  {
    path: '/',
    component: Layout,
    redirect: '/index',
    children: [{
      path: 'index',
      name: 'index',
      component: Home,
      meta: { title: '首页', icon: 'iconfont iconzu925' }
    }]
  },
  {
    path: '/a',
    component: Layout,
    children: [{
      path: 'index',
      name: 'index',
      component: Home,
      meta: { title: '部门信息', icon: 'iconfont iconzu925' },
    }]
  }
]

// const error = [{ path: '*', name: '404', component: () => import('@/views/404.vue'), hidden: true, meta: { title: '404' } }]

export const asyncRoutes = []
// 路由组合 按侧边导航顺序来
export const constantRoutes = [
  ...routine // 基础
]

const createRouter = () => new Router({
  mode: 'history',
  base: process.env.BASE_URL,
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})
const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}
export default router
